package org.eclipse.mylyn.rememberthemilk.core;

import static org.junit.Assert.*;

import org.eclipse.mylyn.rememberthemilk.core.RTMCorePlugin;
import org.eclipse.mylyn.rememberthemilk.core.exceptions.RTMException;
import org.eclipse.mylyn.rememberthemilk.ui.RTMTaskEditorPageFactory;
import org.eclipse.mylyn.rememberthemilk.ui.editors.RTMTaskEditorPage;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
import org.eclipse.ui.forms.editor.IFormPage;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class RTMTaskEditorPageFactoryTests extends BaseRtmTests {
	Mockery context = new Mockery() {{
		setImposteriser(ClassImposteriser.INSTANCE);
	}};
	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testCanCreatePageFor() {
		RTMTaskEditorPageFactory factory = new RTMTaskEditorPageFactory();
		final TaskEditorInput input = context.mock(TaskEditorInput.class);
		
		context.checking(new Expectations() {{
			oneOf(input).getTaskRepository(); will(returnValue(createTaskRepository()));
		}});
		
		boolean isCapable = factory.canCreatePageFor(input);
		assertTrue("Factory incapable of making page", isCapable);
	}

	@Test
	public void testCreatePage() {
		RTMTaskEditorPageFactory factory = new RTMTaskEditorPageFactory();
		
		TaskEditor parentEditor = context.mock(TaskEditor.class);
		IFormPage editor = factory.createPage(parentEditor);
		assertNotNull("no editor created", editor); 
		assertEquals("classes where different", RTMTaskEditorPage.class, editor.getClass());
	}
}
